import React, { Component, Fragment } from 'react';
import { connect } from 'dva'
import BaseTable from './baseTable'
import { Space, Popconfirm } from 'antd'

class TechnologyTable extends BaseTable {
    constructor(props) {
        super(props),
            this.state = {
                column: [
                    { title: "技术编号", dataIndex: "id", key: "id", width: 150, ...this.getColumnSearchProps('id') },
                    { title: "技术名称", dataIndex: "technologyName", key: "technologyName", ...this.getColumnSearchProps('technologyName') },
                    {
                        title: "当前阶段", dataIndex: "verificationPhase", key: "verificationPhase",
                        filters: [
                            { text: "资格审查", value: 1 },
                            { text: "验证审查", value: 2 },
                            { text: "签订验证协议", value: 3 },
                            { text: "测试数据", value: 4 },
                            { text: "验证", value: 5 },
                            { text: "审查验证报告", value: 6 },
                            { text: "完成验证", value: 7 },
                        ],
                        onFilter: (value, record) => record.verificationTechnology.verificationPhase == value,
                        render: (text, record, index) => {
                            switch (record.verificationTechnology.verificationPhase) {
                                case 1:
                                    return "资格审查"
                                    break;
                                case 2:
                                    return "验证审查"
                                    break;
                                case 3:
                                    return "签订验证协议"
                                    break;
                                case 4:
                                    return "测试数据"
                                    break;
                                case 5:
                                    return "验证"
                                    break;
                                case 6:
                                    return "审查验证报告"
                                    break;
                                case 7:
                                    return "完成验证"
                                    break;
                            }
                        }
                    },
                    {
                        title: '操作', dataIndex: 'action', key: 'action',
                        render: (text, record, index) => {
                            return (
                                <Space key={index}>
                                    <a onClick={() => { this.search(record.id) }}>查看</a>
                                    <Popconfirm
                                        title="确定删除此条技术申请数据吗？删除后所有数据文件将不可恢复"
                                        onConfirm={() => { this.delete(record.id) }}
                                        placement="leftTop"
                                        okText="确定"
                                        cancelText="取消"
                                    >
                                        <a>删除</a>
                                    </Popconfirm>
                                </Space>
                            )
                        }
                    }
                ]
            }
    }

    search = id => {
        this.props.dispatch({
            type: "application/getVerificationPhaseByTechnologyId",
            data: {
                id: id
            }
        })
    }

    delete = id => {
        this.props.dispatch({
            type: "application/deleteVerificationByTechnologyId",
            data: {
                verificationApplicationId: id
            }
        })

        this.props.dispatch({
            type: 'application/getVerificationListByUserId',
            data: { userId: this.props.user.id }
        })
    }

    render() {
        return super.render(this.state.column, this.props.dataSource, { pageSize: 12 })
    }
}

const mapStateToProps = state => {
    let dataSource = state.application.verificationList
    let user = state.app.user
    return {
        dataSource,
        user
    }
}

export default connect(mapStateToProps)(TechnologyTable)